
#ceph单节点一键部署
#by 神崎长闲
echo "-------------------------------------------------"
echo "-------------------------------------------------"
echo "----------- ceph单节点一键部署   -----------------"
echo "------------     by神崎长闲      ----------------"
echo "------------------------------------------------"
echo "------------------------------------------------"

echo -n "----配置iptables----"
systemctl stop firewalld > /dev/null 2>&1
systemctl disable firewalld  > /dev/null 2>&1
if [ $? -eq 0 ];then
echo -n "----Iptables初始化完毕----"
fi
 
echo "----关闭SELinux----"
setenforce 0 > /dev/null 2>&1
sed -i '/^SELINUX=/s/=.*/=disabled/' /etc/selinux/config
if [ $? -eq 0 ];then
        echo -n "----SELinux初始化完毕----"
fi

 
echo "----重置主机名----"
HOSTNAME=ceph
hostnamectl set-hostname ceph
IP=`ip route |grep src|grep metric|awk -F" " '{ print $9 }'`
echo "$IP $HOSTNAME" >>/etc/hosts
echo "----安装epel额外源----"
yum install -y epel-release
 
echo "----增加ceph网易源----"
cat <<EOF > /etc/yum.repos.d/ceph.repo
[Ceph]
name=Ceph packages for $basearch
baseurl=http://mirrors.163.com/ceph/rpm-jewel/el7/x86_64
enabled=1
gpgcheck=1
type=rpm-md
gpgkey=http://mirrors.163.com/ceph/keys/release.asc
priority=1
 
[Ceph-noarch]
name=Ceph noarch packages
baseurl=http://mirrors.163.com/ceph/rpm-jewel/el7/noarch
enabled=1
gpgcheck=1
type=rpm-md
gpgkey=http://mirrors.163.com/ceph/keys/release.asc
priority=1
 
[ceph-source]
name=Ceph source packages
baseurl=http://mirrors.163.com/ceph/rpm-jewel/el7/SRPMS
enabled=1
gpgcheck=1
type=rpm-md
gpgkey=http://mirrors.163.com/ceph/keys/release.asc
priority=1
 
EOF
 
echo "----更新&&清理缓存&&安装ceph-deploy----"
yum update -y &&yum clean all &&yum -y install ceph-deploy
 
ssh-keygen -t rsa -P "" -f ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
echo "----ceph服务初始化----"
yum clean all &&yum -y install ceph-deploy
 
echo "----创建ceph目录----"
mkdir /etc/ceph &&cd /etc/ceph
ceph-deploy new ceph
echo "----修改配置文件----"
cp ceph.conf ceph.conf.bak
sed -i 's@^$@osd_pool_default_size = 1@g' ceph.conf
echo "mon_pg_warn_max_per_osd = 1000" >> /etc/ceph/ceph.conf
 
echo "----安装ceph----"
ceph-deploy install ceph
echo "----创建monitor服务----"
ceph-deploy mon create ceph
ceph-deploy  gatherkeys ceph
echo "----osd部分----"
echo "----准备osd----"
echo "----挂载sdb磁盘----"
mkfs.xfs  /dev/sdb
mkdir -p /var/local/osd
mount /dev/sdb  /var/local/osd/
chown -R ceph:ceph /var/local/osd*
echo "----创建osd----"
ceph-deploy osd prepare ceph:/var/local/osd
echo "----激活osd----"
ceph-deploy osd activate ceph:/var/local/osd
echo "----查看状态----"
ceph-deploy osd list ceph
echo "----修改配置文件权限----"
 
ceph-deploy admin ceph
chmod +r /etc/ceph/*
echo "----部署mds服务----"
 
ceph-deploy mds create ceph
ceph mds stat
echo "----创建ceph文件系统----"
 
ceph fs ls
ceph osd pool create cephfs_data 128
ceph osd pool create cephfs_metadata 128
ceph fs new cephfs cephfs_metadata cephfs_data
ceph fs ls
echo "----挂载ceph文件系统----"
 
mkdir /ceph
yum install -y ceph-fuse
IP=`ip route |grep src|grep metric|awk -F" " '{ print $9 }'`
ceph-fuse -m $IP:6789/ /ceph
df -Th
echo "----查看ceph状态----" 
echo "----1.mon状态"
 
ceph mon stat 
echo "----2.osd状态"
ceph osd stat 
echo "----3.sod树状图"
ceph osd tree 
ceph pg stat 
 
ssh -o stricthostkeychecking=no $HOSTNAME
